package com.alibaba.citrus.ots.b2b.trade.order.functions.orderLine.entity;


import com.alibaba.citrus.ots.b2b.trade.order.repository.OrderLineWriteRepository;
import com.alibaba.citrus.ots.common.util.SpringContextUtil;
import com.epoch.app.otsb2btradecenter.enums.OrderStatus;
import com.epoch.app.otsb2btradecenter.sdo.OrderLineSDO;
import lombok.Getter;

@Getter
public class OrderLineWriteEntity {

    private OrderLineSDO orderLineSDO;

    private static  OrderLineWriteRepository orderLineWriteRepository;

    static {
        orderLineWriteRepository = SpringContextUtil.getBean(OrderLineWriteRepository.class);
    }

    public static OrderLineWriteEntity of(OrderLineSDO orderLineSDO) {
        OrderLineWriteEntity orderLineWriteEntity = new OrderLineWriteEntity();
        orderLineWriteEntity.orderLineSDO = orderLineSDO;
        return orderLineWriteEntity;
    }

    public String remove(){
        return orderLineWriteRepository.remove(this.orderLineSDO);
    }

    public Boolean modify() {
        Boolean result = orderLineWriteRepository.modify(this.orderLineSDO);
        if (result = true) {
            return true;
        }
        return false;
    }

    public String save() {
        orderLineSDO.setStatus(OrderStatus.BEFORE_SUBMIT.getCode());
        orderLineSDO.setSyncVersion(0);
        String id = orderLineWriteRepository.save(orderLineSDO);
        return id;
    }

    /**
     * 修改销售子单状态及features
     * @return
     */
    public Boolean modifyStatus() {
        return orderLineWriteRepository.modifyStatus(this.orderLineSDO);
    }
}
